/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2011 All Rights Reserved.
 */
package com.alipay.supergw.common.dal.share_supergw.auto.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.alibaba.common.lang.Paginator;
import com.alipay.supergw.common.dal.share_supergw.auto.daointerface.AssembleTemplateDAO;
import com.alipay.supergw.common.dal.share_supergw.auto.dataobject.AssembleTemplateDO;
import com.iwallet.biz.common.util.PageList;

/**
 * An ibatis based implementation of dao interface <tt>com.alipay.supergw.common.dal.share_supergw.auto.daointerface.AssembleTemplateDAO</tt>.
 *
 * This file is generated by <tt>supergw-dalgen</tt>, a DAL (Data Access Layer)
 * code generation utility specially developed for <tt>supergw</tt> project.
 * 
 * PLEASE DO NOT MODIFY THIS FILE MANUALLY, or else your modification may
 * be OVERWRITTEN by someone else. To modify the file, you should go to 
 * directory <tt>(project-home)/dalgen</tt>, and 
 * find the corresponding configuration file (<tt>tables/sgw_assemble_template.xml</tt>). 
 * Modify the configuration file according to your needs, then run <tt>supergw-dalgen</tt> 
 * to generate this file.
 */
public class IbatisAssembleTemplateDAO extends SqlMapClientDaoSupport implements
                                                                     AssembleTemplateDAO {

    /**
     *  Query DB table <tt>sgw_assemble_template</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select id, out_trans_code_id, template_type, template_content, sub_template_1, sub_template_2, header_template, message_type, channel_system_id, gmt_create, gmt_modified from sgw_assemble_template</tt>
     *
     *	@return List<AssembleTemplateDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings("unchecked")
    public List<AssembleTemplateDO> loadAll() throws DataAccessException {

        return getSqlMapClientTemplate().queryForList("MS-ASSEMBLE-TEMPLATE-LOAD-ALL", null);

    }

    /**
     *  Insert one <tt>AssembleTemplateDO</tt> object to DB table <tt>sgw_assemble_template</tt>, return primary key
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>insert into sgw_assemble_template(id,out_trans_code_id,template_type,template_content,sub_template_1,sub_template_2,header_template,message_type,channel_system_id,gmt_create,gmt_modified) values (?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate, sysdate)</tt>
     *
     *	@param assembleTemplate
     *	@return int
     *	@throws DataAccessException
     */
    public int insert(AssembleTemplateDO assembleTemplate) throws DataAccessException {
        if (assembleTemplate == null) {
            throw new IllegalArgumentException("Can't insert a null data object into db.");
        }

        getSqlMapClientTemplate().insert("MS-ASSEMBLE-TEMPLATE-INSERT", assembleTemplate);

        return assembleTemplate.getId();
    }

    /**
     *  Query DB table <tt>sgw_assemble_template</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select id, out_trans_code_id, template_type, template_content, sub_template_1, sub_template_2, header_template, gmt_create, gmt_modified, message_type, channel_system_id from sgw_assemble_template where ((out_trans_code_id = ?) AND (message_type = ?) AND (template_type = ?))</tt>
     *
     *	@param outTransCodeId
     *	@param messageType
     *	@param templateType
     *	@return List<AssembleTemplateDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings( { "rawtypes", "unchecked" })
    public List<AssembleTemplateDO> select(String outTransCodeId, String messageType,
                                           String templateType) throws DataAccessException {
        Map param = new HashMap();

        param.put("outTransCodeId", outTransCodeId);
        param.put("messageType", messageType);
        param.put("templateType", templateType);

        return getSqlMapClientTemplate().queryForList("MS-ASSEMBLE-TEMPLATE-SELECT", param);

    }

    /**
     *  Update DB table <tt>sgw_assemble_template</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>update sgw_assemble_template set out_trans_code_id=?, template_type=?, template_content=?, sub_template_1=?, sub_template_2=?, header_template=?, message_type=?, channel_system_id=?, gmt_modified=sysdate where (id = ?)</tt>
     *
     *	@param outTransCodeId
     *	@param templateType
     *	@param templateContent
     *	@param subTemplate1
     *	@param subTemplate2
     *	@param headerTemplate
     *	@param messageType
     *	@param channelSystemId
     *	@param id
     *	@return int
     *	@throws DataAccessException
     */
    @SuppressWarnings( { "rawtypes", "unchecked" })
    public int update(String outTransCodeId, String templateType, String templateContent,
                      String subTemplate1, String subTemplate2, String headerTemplate,
                      String messageType, String channelSystemId, int id)
                                                                         throws DataAccessException {
        Map param = new HashMap();

        param.put("outTransCodeId", outTransCodeId);
        param.put("templateType", templateType);
        param.put("templateContent", templateContent);
        param.put("subTemplate1", subTemplate1);
        param.put("subTemplate2", subTemplate2);
        param.put("headerTemplate", headerTemplate);
        param.put("messageType", messageType);
        param.put("channelSystemId", channelSystemId);
        param.put("id", new Integer(id));

        return getSqlMapClientTemplate().update("MS-ASSEMBLE-TEMPLATE-UPDATE", param);
    }

    /**
     *  Delete records from DB table <tt>sgw_assemble_template</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>delete from sgw_assemble_template where (id = ?)</tt>
     *
     *	@param id
     *	@return int
     *	@throws DataAccessException
     */
    public int delete(int id) throws DataAccessException {
        Integer param = new Integer(id);

        return getSqlMapClientTemplate().delete("MS-ASSEMBLE-TEMPLATE-DELETE", param);
    }

    /**
     *  Update DB table <tt>sgw_assemble_template</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select id, out_trans_code_id, template_type, template_content, sub_template_1, sub_template_2, header_template, gmt_create, gmt_modified, message_type, channel_system_id from sgw_assemble_template where (id = ?)</tt>
     *
     *  @param id
     *  @return AssembleTemplateDO
     *  @throws DataAccessException
     */
    public AssembleTemplateDO selectById(int id) throws DataAccessException {
        Integer param = new Integer(id);

        return (AssembleTemplateDO) getSqlMapClientTemplate().queryForObject(
            "MS-ASSEMBLE-TEMPLATE-SELECT-BY-ID", param);
    }

    /**
     *  Update DB table <tt>sgw_assemble_template</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select id, out_trans_code_id, template_type, template_content, sub_template_1, sub_template_2, header_template, gmt_create, gmt_modified, message_type, channel_system_id from sgw_assemble_template</tt>
     *
     *  @param templateType
     *  @param pageSize
     *  @param pageNum
     *  @return PageList
     *  @throws DataAccessException
     */
    @SuppressWarnings( { "rawtypes", "unchecked" })
    public PageList selectPage(String templateType, int pageSize, int pageNum)
                                                                              throws DataAccessException {
        Map param = new HashMap();

        param.put("templateType", templateType);
        param.put("pageSize", new Integer(pageSize));
        param.put("pageNum", new Integer(pageNum));

        Paginator paginator = new Paginator();
        paginator.setItemsPerPage(pageSize);
        paginator.setPage(pageNum);

        paginator.setItems(((Integer) getSqlMapClientTemplate().queryForObject(
            "MS-ASSEMBLE-TEMPLATE-SELECT-COUNT-FOR-PAGING", param)).intValue());

        PageList pageList = new PageList();
        pageList.setPaginator(paginator);

        if (paginator.getBeginIndex() <= paginator.getItems()) {
            param.put("startRow", new Integer(paginator.getBeginIndex() == 0 ? 0 : paginator
                .getBeginIndex() - 1));
            param.put("endRow", new Integer(10));
            pageList.addAll(getSqlMapClientTemplate().queryForList(
                "MS-ASSEMBLE-TEMPLATE-SELECT-FOR-PAGING", param));
        }

        return pageList;
    }

}